# -*- coding:utf-8 -*-
import scrapy

from tmgood.items import TmgoodItem
from bs4 import BeautifulSoup

class tmspider(scrapy.Spider):
    name = "tmg"
    start_urls = (
        'https://list.tmall.com/search_product.htm?spm=a220m.1000858.1000724.9.611598c4USX7Te&cat=50025174&q=%C4%D0%CA%BF%B3%C4%C9%C0%B3%A4%D0%E4&sort=s&style=l&from=mallfp..pc_1_suggest&suggest=0_1&active=2#J_Filter',
    )
    def parse(self,response):
        item = TmgoodItem()
        item["name"] = response.xpath("/html/head/title/text()")

        divlis = response.xpath("//div[@id='J_ItemList']/div[@class='product']")

        nexturl = response.xpath("//div[@id='J_bottomPage']").xpath(".//a[@class='pn-next']/@href")
        print("nexturl:",nexturl)

        divlis = response.xpath("//div[@id='J_goodsList']/ul/li")
        print (333)
        print(item["name"])
        print("ceshi")


        for xp in divlis:
            pri = xp.xpath("@data-id").extract()
            print (pri)
        # item["title"] = divlis[1].xpath("./li/@data-sku")
        # soup = BeautifulSoup(response.body,"html5lib")
        # sop1 = soup.find("div",id="J_goodsList")
        # sop2 = sop1.find_all("li" , class_="gl-item")
        # sop3 = sop2[1].find("div",class_="p-name")
        # sop4 = sop3.find("em")
        # sop5 = sop2[0].get("data-sku")
        # print (len(soup))
        # print (len(sop2))
        # print (sop4)
        # print (sop5)
        # print (len(divlis))
        # print (divlis[0])
        # print (divlis[1])
        # print (divlis[2])
        # print (item["title"][1])